Repository navigation
Fix the weight and sign of base 60 scalars - #832
Open
ihamzatarar wants to merge 1 commit into
Open
ihamzatarar wants to merge 1 commit into
ihamzatarar wants to merge 1 commit into
Conversation
ScalarScanner resolved a base 60 scalar with a positional weight of 60 ** (index - 2).abs, which is only correct for three components. A two component value such as 12:30 was weighted 3600 and 60 rather than 60 and 1, so it came out sixty times too large, and 12:30 and 12:30:00 loaded to the same value. The sign was also taken from the first component alone, because the minus stays on the first element of the split, so -12:30:00 resolved to -12*3600 + 30*60 + 0, that is -41400 rather than -45000. Take the weight from the number of components that follow, and apply the sign to the total. PyYAML resolves all of these the same way.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #814.
ScalarScanner#tokenizeresolved a base 60 scalar withwhich carries two separate faults.
The weight assumes three components.
(e - 2).absgives 3600, 60, 1 for a three component value, but 3600, 60 for a two component one, so12:30came out as12*3600 + 30*60, sixty times too large. A consequence is that12:30and12:30:00loaded to the same value, although they are different documents.The sign reaches only the first component.
"-12:30:00".split(':')is["-12", "30", "00"], so the result was-12*3600 + 30*60 + 0, that is-41400rather than-45000. Any negative value with a non-zero trailing component had the wrong magnitude, independently of the first fault.The weight now comes from how many components follow, and the sign is applied to the total.
Checked against another YAML 1.1 implementation
PyYAML 6.0.3 resolves the same scalars, and agrees with this patch on every case, including the ones beyond those reported:
12:301:30100:0012:30.5-12:30-12:30:00-12:30.5+12:3012:30:00.51_0:3012:30:001:00:00The last two are the three component cases that were already right, and they are unchanged.
Tests
test/psych/test_scalar_scanner.rbalready covered the three component forms,190:20:30and190:20:30.15, which is why this went unnoticed. Three tests are added beside them: two component values, negative values, and one asserting that12:30and12:30:00no longer resolve alike.All three fail on master. The file passes with the change: